import {
  Modal,
  Form,
  Button,
  Input,
  Select,
  DatePicker,
  Radio,
  InputNumber
} from 'antd';
import React from 'react';
import List from "./List";

const FormItem = Form.Item;
const Option = Select.Option;
const RadioGroup = Radio.Group;
const doRecharge1 = ({
  outlineRecharge,
  distributors,
  dispatch,
  rechargeLogId,
  rechargePath,
  currentType,
  shops,
  outlineCashInitValue,
  offOrOnline,
  onOk,
  currentTenant,
  currentTenantId,
  form: {
    getFieldDecorator,
    validateFieldsAndScroll,
  },
  ...doRechargeProps,
}) => {
  const handleCancel = () => {
    outlineRecharge(false)
  };
  const handleOk = (e) => {
    e.preventDefault();
    validateFieldsAndScroll((err, values) => {
      if (!err) {
        if (offOrOnline === "offline") {
          values.paymentTime = Date.parse(new Date(values.paymentTime));
          values.arrivedTime = Date.parse(new Date(values.arrivedTime));
          values.shopName = currentTenant;
          values.businessType = '8';
          values.billRecordType = '预付款';
          values.paymentType = '网银';
          Modal.confirm({
            title: '请确认充值信息',
            content: '充值金额：' + values.paymentMoney,
            onOk: () => {
              onOk(values);
            },
            okText: '充值',
            cancelText: '取消'
          })
        } else if (offOrOnline === "online") {
          dispatch({
            type: 'recharge/tenantRecharge',
            payload: {
              ...values,
              rechargeId: rechargeLogId,
              payMoney: values.amountMoney,
              payerId: currentTenantId,
              showUrl: window.location.href,
              chargeType: 'TENANT_RECHARGE',
              paymentReceiptType: 'TENANT_CHARGE'
            }
          })
        }
      }
    });
  };

  return (
    <Form >
      <Modal
        visible={doRechargeProps.visible}
        title="充值"
        onCancel={handleCancel}
        footer={[
          <Button key="back" onClick={handleCancel}>取消</Button>,
          <Button key="submit" type="primary" htmlType="submit" onClick={handleOk} >
            充值
            </Button>,
        ]}
        width={430}
        destroyOnClose={true}>
        {offOrOnline === "offline" && <div>
          <FormItem
            label="付款方"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('shopName')(
              <span>{currentTenant}</span>
            )}
          </FormItem>
          <FormItem
            label="业务类型"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('businessType')(
              <span>分销预付款-线下</span>
            )}
          </FormItem>
          <FormItem
            label="资金流水类型"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('billRecordType')(
              <span>预付款</span>
            )}
          </FormItem>
          <FormItem
            label="支付方式"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('paymentType')(
              <span>网银</span>
            )}
          </FormItem>
          <FormItem
            label="付款时间"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('paymentTime', {
              rules: [
                {
                  required: true,
                  message: '请选择付款时间'
                }
              ]
            })(<DatePicker style={{
              width: '100%'
            }} />)}
          </FormItem>
          <FormItem
            label="到账时间"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('arrivedTime', {
              rules: [
                {
                  required: true,
                  message: '请选择到账时间'
                }
              ]
            })(<DatePicker style={{
              width: '100%'
            }} />)}
          </FormItem>
          <FormItem
            label="支付凭证号:"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('paymentNum', {
              rules: [
                {
                  required: true,
                  message: '此项不能为空'
                }
              ],
              initialValue: ""
            })(<Input />)}
          </FormItem>
          <FormItem
            label="付款金额"
            labelCol={{
              span: 7
            }}
            wrapperCol={{
              span: 15
            }}>
            {getFieldDecorator('paymentMoney', {
              rules: [
                {
                  required: true,
                  message: '请输入正确的金额'
                }
              ],
              validateTrigger: "onSubmit"
            })(<InputNumber min={0} />)
            }
          </FormItem>
        </div>}
        {offOrOnline === "online" && <FormItem
          label="付款金额"
          labelCol={{
            span: 5
          }}
          wrapperCol={{
            span: 28
          }}>
          {getFieldDecorator('amountMoney', {
            rules: [
              {
                required: true,
                message: '请输入正确的金额'
              }
            ],
            validateTrigger: "onSubmit"
          })(<RadioGroup>
            <Radio value="5000">5000</Radio>
            <Radio value="10000">10000</Radio>
            <Radio value="20000">20000</Radio>
            <Radio value="50000">50000</Radio>
          </RadioGroup>)
          }
        </FormItem>}

      </Modal>
    </Form>
  );
};
export default Form.create()(doRecharge1);
